﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Portal.Xml.Utility;

namespace Portal.Systems.Model
{
    public class PageZoneModuleCls
    {
        public string ServiceId;
        public string PageZoneModuleId;
        public string PageZoneId;
        public string ModuleId;
        public string ModuleTitle;
        public string AssetCode;
        public string DataLanguage;
        public int Visible;
        public int SortIndex;
        public string PageId;
        public string PlugInViewId;
        public string CssClass = "";
        public string XmlDataConfig = "";
    }

    public class PageZoneModuleParser
    {
        public static PageZoneModuleCls CreateInstance()
        {
            //tao 1 class trang....
            PageZoneModuleCls oPageZoneModuleCls = new PageZoneModuleCls();
            return oPageZoneModuleCls;
        }

        public static PageZoneModuleCls ParseFromXml(string XmlData)
        {
            DataSet ds = XmlUtility.GetDataSetFromXml(XmlData);
            PageZoneModuleCls oPageZoneModuleCls = ParseFromDataRow(ds.Tables[0].Rows[0]);
            return oPageZoneModuleCls;
        }


        public static PageZoneModuleCls ParseFromDataRow(DataRow dr)
        {
            PageZoneModuleCls OPageZoneModuleCls = new PageZoneModuleCls();
            OPageZoneModuleCls.ServiceId = XmlUtility.GetString(dr, "ServiceId", true);
            OPageZoneModuleCls.PageZoneModuleId = XmlUtility.GetString(dr, "PageZoneModuleId", true);
            OPageZoneModuleCls.PageZoneId = XmlUtility.GetString(dr, "frkPageZoneId", true);
            OPageZoneModuleCls.ModuleId = XmlUtility.GetString(dr, "ModuleId", true);
            OPageZoneModuleCls.ModuleTitle = XmlUtility.GetString(dr, "ModuleTitle", true);
            OPageZoneModuleCls.AssetCode = XmlUtility.GetString(dr,"AssetCode",true);
            OPageZoneModuleCls.DataLanguage = XmlUtility.GetString(dr, "DataLanguage", true);
            OPageZoneModuleCls.Visible = XmlUtility.GetInt(dr, "Visible", true);
            OPageZoneModuleCls.SortIndex = XmlUtility.GetInt(dr, "SortIndex", true);
            OPageZoneModuleCls.PageId = XmlUtility.GetString(dr, "PageId", true);
            OPageZoneModuleCls.PlugInViewId = XmlUtility.GetString(dr, "PlugInViewId", true);
            OPageZoneModuleCls.CssClass = XmlUtility.GetString(dr, "CssClass", true);
            OPageZoneModuleCls.XmlDataConfig = XmlUtility.GetString(dr, "XmlDataConfig", true);
            return OPageZoneModuleCls;
        }


        public static PageZoneModuleCls ParseFromDataRowView(DataRowView dv)
        {
            PageZoneModuleCls OPageZoneModuleCls = new PageZoneModuleCls();
            OPageZoneModuleCls.ServiceId = XmlUtility.GetString(dv, "ServiceId", true);
            OPageZoneModuleCls.PageZoneModuleId = XmlUtility.GetString(dv, "PageZoneModuleId", true);
            OPageZoneModuleCls.PageZoneId = XmlUtility.GetString(dv, "frkPageZoneId", true);
            OPageZoneModuleCls.ModuleId = XmlUtility.GetString(dv, "ModuleId", true);
            OPageZoneModuleCls.ModuleTitle = XmlUtility.GetString(dv, "ModuleTitle", true);
            OPageZoneModuleCls.AssetCode = XmlUtility.GetString(dv, "AssetCode", true);
            OPageZoneModuleCls.DataLanguage = XmlUtility.GetString(dv, "DataLanguage", true);
            OPageZoneModuleCls.Visible = XmlUtility.GetInt(dv, "Visible", true);
            OPageZoneModuleCls.SortIndex = XmlUtility.GetInt(dv, "SortIndex", true);
            OPageZoneModuleCls.PageId = XmlUtility.GetString(dv, "PageId", true);
            OPageZoneModuleCls.PlugInViewId = XmlUtility.GetString(dv, "PlugInViewId", true);
            OPageZoneModuleCls.CssClass = XmlUtility.GetString(dv, "CssClass", true);
            OPageZoneModuleCls.XmlDataConfig = XmlUtility.GetString(dv, "XmlDataConfig", true);
            return OPageZoneModuleCls;
        }

        public static PageZoneModuleCls[] ParseFromDataTable(DataTable dtTable)
        {
            PageZoneModuleCls[] PageZoneModules = new PageZoneModuleCls[dtTable.Rows.Count];
            for (int iIndex = 0; iIndex < dtTable.Rows.Count; iIndex++)
            {
                PageZoneModules[iIndex] = ParseFromDataRow(dtTable.Rows[iIndex]);
            }

            return PageZoneModules;
        }
    }
}


